const koa = require("koa");
const static = require("koa-static");
const path = require("path");
const bodyParser = require("koa-bodyparser");
const indexRouter = require("./routers/indexRouter");
// 引入http的创建服务器方法
const { createServer } = require("http");

const app = new koa();
const httpServer = createServer(app.callback());
//引入socketServer模块
const socketServer = require("./service/socketService");
// 把需要的httpServer传进去
socketServer(httpServer);
// 获取post数据
app.use(bodyParser());
// 静态资源
app.use(static(path.join(__dirname, "public")));
// 路由
app.use(indexRouter.routes());

// 监听
httpServer.listen(3000, () => {
  console.log("server start");
});
